home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / files / standard file / customputappend / initmac.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.8 KB  |  148 lines

  1. /*
  2.     File:        InitMac.c
  3.  
  4.     Contains:    A simple set of routines to initialize the various
  5.                 managers ang check Gestalt for Color QuickDraw
  6.  
  7.     Written by: David Hayward    
  8.  
  9.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/1/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 5/12/95                        updated project for Metrowerks
  22.                 2/27/94                        first draft
  23. */
  24.  
  25. #include <Dialogs.h>
  26. #include <Memory.h>
  27. #include <Windows.h>
  28. #include <QuickDraw.h>
  29. #include <Fonts.h>
  30. #include <GestaltEQU.h>
  31. #include <Traps.h>
  32. #include <TextEdit.h>
  33. #include <OSUtils.h>
  34.  
  35. #include "InitMac.h"
  36.  
  37. #define TrapMask 0x0800
  38.  
  39.  
  40. /**\
  41. |**| ==============================================================================
  42. |**| GLOBALS
  43. |**| ==============================================================================
  44. \**/
  45. SysEnvRec    TheWorld;
  46. Boolean        WNE_available;
  47. Boolean        HasGWorlds;
  48. Boolean        HasCQD;
  49.  
  50.  
  51.  
  52. /*------------------------------------------------------------------------------*\
  53.     NumToolboxTraps
  54. \*------------------------------------------------------------------------------*/
  55. short NumToolboxTraps (void)
  56. {
  57.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  58.             NGetTrapAddress(0xAA6E, ToolTrap))
  59.         return(0x0200);
  60.     else
  61.         return(0x0400);
  62. }
  63.  
  64.  
  65. /*------------------------------------------------------------------------------*\
  66.     GetTrapType
  67. \*------------------------------------------------------------------------------*/
  68. TrapType GetTrapType (short theTrap)
  69. {
  70.     if ((theTrap & TrapMask) > 0)
  71.         return(ToolTrap);
  72.     else
  73.         return(OSTrap);
  74. }
  75.  
  76.  
  77. /*------------------------------------------------------------------------------*\
  78.     TrapAvailable
  79. \*------------------------------------------------------------------------------*/
  80. Boolean TrapAvailable (short theTrap)
  81. {
  82.  
  83.     TrapType    tType;
  84.  
  85.     tType = GetTrapType(theTrap);
  86.     if (tType == ToolTrap)
  87.         theTrap &= 0x07FF;
  88.     if (theTrap >= NumToolboxTraps())
  89.         theTrap = _Unimplemented;
  90.  
  91.     return (NGetTrapAddress(theTrap, tType) !=
  92.             NGetTrapAddress(_Unimplemented, ToolTrap));
  93. }
  94.  
  95.  
  96. /*------------------------------------------------------------------------------*\
  97.     WNEAvailable
  98. \*------------------------------------------------------------------------------*/
  99. Boolean WNEAvailable (void)
  100. {
  101.     return TrapAvailable(_WaitNextEvent);
  102. }
  103.  
  104.  
  105. /*------------------------------------------------------------------------------*\
  106.     CheckQuickDraw
  107. \*------------------------------------------------------------------------------*/
  108. void CheckQuickDraw (void)
  109. {
  110.     long      QDvers;  /* Version of QuickDraw on this machine */
  111.     
  112.     /* Find out if GWorlds and CQD are implemented on this machine */
  113.     Gestalt(gestaltQuickdrawVersion, &QDvers);
  114.  
  115.     HasGWorlds = (QDvers > gestaltOriginalQD && QDvers < gestalt8BitQD)
  116.                   || QDvers >= gestalt32BitQD;
  117.     
  118.     HasCQD = (QDvers >= gestalt8BitQD);
  119. }
  120.  
  121.  
  122. /*------------------------------------------------------------------------------*\
  123.     InitToolBox
  124. \*------------------------------------------------------------------------------*/
  125. void InitToolBox (short numberOfMasters)
  126. {
  127.     
  128.     InitGraf((Ptr) &qd.thePort);
  129.     InitFonts();
  130.     InitWindows();
  131.     InitMenus();
  132.     InitCursor();
  133.     TEInit();
  134.     FlushEvents(everyEvent, 0);
  135.     InitDialogs(nil);
  136.     
  137.     while(numberOfMasters--)
  138.         MoreMasters();
  139.         
  140.     MaxApplZone();
  141.     
  142.     SysEnvirons(1,&TheWorld);
  143.     
  144.     WNE_available = WNEAvailable();
  145.  
  146.     CheckQuickDraw ();
  147. }
  148.